<%@page import="com.surelution.projects.crm.NoGasTypeCategory"%>
<%@page import="com.surelution.projects.crm.GasType"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main"/>
<g:set var="entityName" value="${message(code: 'gasList.label', default: 'gasList')}" />
<g:javascript library="jquery"/>
<resource:dateChooser />
<link rel="stylesheet" href="${resource(dir:'css',file:'defaultTheme.css')}" />

<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.printElement.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.fixedheadertable.min.js')}"></script>
<title><g:message code="default.dayReport.label" args="[entityName]" /></title>
	<script type="text/javascript">
		$(document).ready(function() {
		   $("#simplePrint").click(function() {
		       printElem({leaveOpen: true, printMode: 'popup', overrideElementCSS: ["${resource(dir:'plugins/richui-0.8/css',file:'calendarmonthview.css')}","${resource(dir:'css',file:'main.css')}"]});
		   });
		   $('#myTable01').fixedHeaderTable({ footer: false, cloneHeadToFoot: false, autoShow: true });
		});
		function printElem(options){
		    $('#report').printElement(options);
		};
		
	</script>
	<script type="text/javascript" src="${resource(dir:'js/datechooser',file:'datechooser.js')}"></script>
</head>

<body>
  <div class="body">
          <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
          </div>
          <div>
            <p style="font-size:16px;color:#000;margin:10px 0;">加油站日报</p>
        	<g:form action="dayReport">
        		选择日期：<richui:dateChooser name="startDay" locale="zh" format="yyyy-MM-dd" value="${startDay}" />
			    <span class="menuButton" style="margin-right:5px;"><g:actionSubmit value="${message(code: 'default.button.search.label', default: 'report')}" action="dayReport"/></span>
    			<span class="menuButton"><g:actionSubmit value="${message(code: 'default.button.export.label', default: 'Export')}" action="dayExportReport"/></span>
			    <input type="button" value="打印报表" id="simplePrint" /><br>
    			选择片区：    				
    			<g:each in="${com.surelution.projects.crm.StationArea.list()}" var="area">
	    			<g:checkBox id="stationArea.id_${area.id }" name="stationArea" value="${area.id }" checked="${stationArea!=[]?stationArea.contains(area.id):true}"/><label for="stationArea.id_${area.id }">${area.areaName}</label>&nbsp;
    			</g:each>			
			</g:form>
			<g:if test="${flash.message}">
            	<div class="message">${flash.message}</div>
            </g:if>
        </div>
        <%
			def t0gasSum=0,t93gasSum=0,t97gasSum=0,tallGasSum=0,tallPlan=0.01,tNoGas1=0,tNoGas2=0,tNoGas3=0,tNoGas4=0,tNoGas5=0,tallNoGasSum=0,tallNoPlan=0
		 %>
        <div style="height:650px;">
			<label style="font-size:16px;color:#0f3072;">报表日期：  ${startDay.format("yyyy年MM月dd日")}</label>
        		<table id="myTable01">
        		<thead>
        			<tr>
	        			<td colspan="3"></td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;" colspan="6">油品</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;" colspan="8">非油品</td>
        			</tr>
	        		<tr>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">序号</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">片区</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">加油站名</td>
        				<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">0#(吨)</td>
        				<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">93#(吨)</td>
        				<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">97#(吨)</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">合计(吨)</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">${startDay.format("MM月")}计划量(吨)</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">计划完成率(%)</td>
	          			<g:each in="${NoGasTypeCategory.list()}" var="l" >
	        				<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">${l.name}(元)</td>
	        			</g:each>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">合计</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">${startDay.format("MM月")}计划量(元)</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">计划完成率(%)</td>
	    			</tr>
	    			
    				<tr class="even">
    					<td style="text-align:center;">合计</td>
    					<td style="text-align:center;width:50px;"></td>
    					<td style="text-align:center;width:100px;"></td>
						<td style="text-align:center;"><div id="t0gasSum"></div></td>
						<td style="text-align:center;"><div id="t93gasSum"></div></td>
						<td style="text-align:center;"><div id="t97gasSum"></div></td>
						<td style="text-align:center;"><div id="tallGasSum"></div></td>
						<td style="text-align:center;"><div id="tallPlan"></div></td>
						<td style="text-align:center;">${gasMonthFinish}%</td>
						<td style="text-align:center;"><div id="tNoGas1"></div></td>
						<td style="text-align:center;"><div id="tNoGas2"></div></td>
						<td style="text-align:center;"><div id="tNoGas3"></div></td>
						<td style="text-align:center;"><div id="tNoGas4"></div></td>
						<td style="text-align:center;"><div id="tNoGas5"></div></td>
						<td style="text-align:center;"><div id="tallNoGasSum"></div></td>
						<td style="text-align:center;"><div id="tallNoPlan"></div></td>
						<td style="text-align:center;">${noGasMonthFinish }%</td>
    				</tr>
	    			</thead>
	    			<tbody>
    				<g:each in="${mapList}" var="r" status="i">
    				<%
						t0gasSum += r.get("0号")
					   	t93gasSum += r.get("93号")
					   	t97gasSum += r.get("97号")
					   	tallGasSum += r.get("all")
					   	tallPlan += r.get("plan")
					   	tNoGas1 += r.get("饮料")
					   	tNoGas2 += r.get("便利店润滑油")
					   	tNoGas3 += r.get("汽车用品")
					   	tNoGas4 += r.get("香烟")
					   	tNoGas5 += r.get("便利店商品")
					   	tallNoGasSum += r.get("noGasAll")
					   	tallNoPlan += r.get("noGasPlan")
				 	%>
					<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
    					<td style="text-align:center;">${i+1}</td>
    					<td style="text-align:center;">${r.get("area")}</td>
    					<td style="text-align:center;"> ${r.get("station")}</td>
						<td style="text-align:center;">${r.get("0号")}</td>
						<td style="text-align:center;">${r.get("93号")}</td>
						<td style="text-align:center;">${r.get("97号")}</td>
						<td style="text-align:center;">${r.get("all")}</td>
						<td style="text-align:center;">${r.get("plan")}</td>
						<td style="text-align:center;">${r.get("allPlan")}</td>
						<g:each in="${NoGasTypeCategory.list()}" var="l" >
	        				<td style="text-align: center;">${r.get(l.name)}</td>
	        			</g:each>
						<td style="text-align:center;">${r.get("noGasAll")}</td>
						<td style="text-align:center;">${r.get("noGasPlan")}</td>
						<td style="text-align:center;">${r.get("allNoGasPlan")}</td>
    				</tr>
    				</g:each>
    				</tbody>
          	</table>
        </div>
        <script type="text/javascript">
			document.getElementById("t0gasSum").innerHTML = '${(formatNumber(number:t0gasSum,maxFractionDigits:1)) }';
			document.getElementById("t93gasSum").innerHTML = '${(formatNumber(number:t93gasSum,maxFractionDigits:1)) }';
			document.getElementById("t97gasSum").innerHTML = '${(formatNumber(number:t97gasSum,maxFractionDigits:1)) }';
			document.getElementById("tallGasSum").innerHTML = '${(formatNumber(number:tallGasSum,maxFractionDigits:1)) }';
			document.getElementById("tallPlan").innerHTML = '${(formatNumber(number:tallPlan,maxFractionDigits:1)) }';
			document.getElementById("tNoGas1").innerHTML = '${(formatNumber(number:tNoGas1,maxFractionDigits:1)) }';
			document.getElementById("tNoGas2").innerHTML = '${(formatNumber(number:tNoGas2,maxFractionDigits:1)) }';
			document.getElementById("tNoGas3").innerHTML = '${(formatNumber(number:tNoGas3,maxFractionDigits:1)) }';
			document.getElementById("tNoGas4").innerHTML = '${(formatNumber(number:tNoGas4,maxFractionDigits:1)) }';
			document.getElementById("tNoGas5").innerHTML = '${(formatNumber(number:tNoGas5,maxFractionDigits:1)) }';
			document.getElementById("tallNoGasSum").innerHTML = '${(formatNumber(number:tallNoGasSum,maxFractionDigits:1)) }';
			document.getElementById("tallNoPlan").innerHTML = '${(formatNumber(number:tallNoPlan,maxFractionDigits:1)) }';
        </script>
    	<g:if test="${mapList==[]}">
           	<div class="message">${message(code: 'default.nofound.message')}</div>
    	</g:if>
    	

  </div>
</body>
</html>